package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

//订单控制层
@RestController
public class OrderController {

    @Autowired
    private OrderService orderServicep;

    //下单功能
    @PostMapping("/order/submit")
    public ResultInfo save(@RequestBody Order order) {

        orderServicep.save(order);

        return ResultInfo.success();
    }

    //  查询订单
    @GetMapping("/order/userPage")
    public ResultInfo list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, Long number,
                           @DateTimeFormat Date beginTime,
                           @DateTimeFormat Date endTime) {
        Page<Order> orderPage = orderServicep.orderPage(page, pageSize, number, beginTime, endTime);

        return ResultInfo.success(orderPage);
    }

}
